#!/bin/bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

sh_dir=$this_script_dir
p2pcpp_home=$(cd $sh_dir/.. && pwd)

echo "-- info, p2pcpp_home is:$p2pcpp_home"

if [ "$1"x  == "1"x ] ; then
    cd $sh_dir/nat_type_checker/service && ./nat_type.sh $p2pcpp_home
elif [ "$1"x == "2"x ] ; then
    cd $p2pcpp_home/../nodultrain && ./runultrain-h.sh
elif [ "$1"x == "3"x ] ; then
    cd $sh_dir/nat_type_checker/service && ./nat_type.sh $p2pcpp_home
    cd $p2pcpp_home/../nodultrain && ./runultrain-h.sh
else
    echo "usage :"
    echo "      $0 1/2/3,1:start p2pcpp; 2:start nodultrain; 3:start 1&2"
fi
